package com.poker.jkiuus.uyrfgd;


import com.google.errorprone.annotations.Keep;
import com.poker.iuious.yhyhjs.jklimj.Feedback;
import com.poker.iuious.yhyhjs.jklimj.FeedbackResponse;
import com.poker.rtyfgh.ApiService;
import com.poker.rtyfgh.NetworkCallback;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

@Keep
public class NetworkUtils {

    private static Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("http://aichat.chen2586.top/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    public static void postFeedback(String userName,String feedbackType, String feedbackContent, final NetworkCallback callback) {
        ApiService service = retrofit.create(ApiService.class);
        
        Feedback feedback = new Feedback();
        feedback.setFeedbackType(feedbackType);
        feedback.setUserName(userName);
        feedback.setFeedbackContent(feedbackContent);

        Call<FeedbackResponse> call = service.postFeedback(feedback);
        call.enqueue(new retrofit2.Callback<FeedbackResponse>() {
            @Override
            public void onResponse(Call<FeedbackResponse> call, retrofit2.Response<FeedbackResponse> response) {
                if (response.isSuccessful()) {

                    callback.onSuccess(response.body());
                } else {

                    callback.onFailure(new IOException("Unexpected code " + response));
                }
            }

            @Override
            public void onFailure(Call<FeedbackResponse> call, Throwable t) {

                callback.onFailure(t);
            }
        });
    }
}
